import request from '@/utils/request'
import requestFile from '@/utils/request-file'
import { formatDateByFmt } from '@/utils/util'
import qs from 'qs'

const prefixUrl = 'web/bill_ad_make/'

// 根据market_id获取点位数据
export function points_from_market(params) {
  return request({
    url: prefixUrl + 'points-from-market',
    method: 'get',
    params
  })
}

// 规格列表
export function list_media_type_spec(params) {
  return request({
    url: prefixUrl + 'list-media-type-spec',
    method: 'get',
    params
  })
}

// 材质列表
export function list_media_pic_type(params) {
  return request({
    url: prefixUrl + 'list-media-pic-type',
    method: 'get',
    params
  })
}

// 列表分页
export function list(params) {
  return request({
    url: prefixUrl + 'list',
    method: 'get',
    params
  })
}

// 列表页-生成链接，弹框数据
export function confirm_list(params) {
  return request({
    url: prefixUrl + 'confirm-list',
    method: 'get',
    params
  })
}

// 详情
export function detail(params) {
  return request({
    url: prefixUrl + 'detail',
    method: 'get',
    params
  })
}

// 获取配送方式
export function get_deliver_type(params) {
  return request({
    url: prefixUrl + 'get-deliver-type',
    method: 'get',
    params
  })
}

// 保存至草稿箱
export function save(data) {
  return request({
    url: prefixUrl + 'save',
    method: 'post',
    data: data,
    content_type: 'json'
  })
}

// 提交
export function begin(data) {
  return request({
    url: prefixUrl + 'begin',
    method: 'put',
    data: data,
    content_type: 'json'
  })
}

// 通过
export function pass(data) {
  return request({
    url: prefixUrl + 'pass',
    method: 'put',
    data: data,
    content_type: 'json'
  })
}

// 驳回
export function return_back(data) {
  return request({
    url: prefixUrl + 'return_back',
    method: 'put',
    data: data,
    content_type: 'json'
  })
}

// 删除
export function remove(params) {
  return request({
    url: prefixUrl + 'delete',
    method: 'delete',
    params
  })
}

// 彻底删除
export function actual_delete(params) {
  return request({
    url: prefixUrl + 'actual_delete',
    method: 'delete',
    params
  })
}

// 生成确认链接
export function generate_confirm_link(data) {
  return request({
    url: prefixUrl + 'generate-confirm-link',
    method: 'put',
    content_type: 'json',
    data
  })
}


// 获取已生成的确认链接
export function get_confirm_link(params) {
  return request({
    url: prefixUrl + 'get-confirm-link',
    method: 'get',
    params
  })
}

// 供应商确认单详情
export function confirm_bill_detail(params) {
  return request({
    url: prefixUrl + 'confirm-bill-detail',
    method: 'get',
    params
  })
}

// 确认单签字
export function sign_confirm_bill(data) {
  return request({
    url: prefixUrl + 'sign-confirm-bill',
    method: 'put',
    content_type: 'json',
    data
  })
}

// 安装导出
export function exportSupplierDataExcel(params) {
  return requestFile({
    url: prefixUrl + '/exportSupplierDataExcel',
    method: 'get',
    params,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    },
    fileName: '制作单导出-供应商清单' + (formatDateByFmt(new Date(), 'yyyyMMddhhmmss') + Math.floor(Math.random() * (
      1000000 -
      1) + 1)) + '.xls'
  })
}
